<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/calendar/ShowDay.class.php
 *
 * 显示日历
 *
 * PHP Version 5
 *
 * @package:   class.calendar
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

include_once CLASS_PATH.'calendar/CalendarUtil.class.php';


class ShowDayData extends BaseAction {
   /**
    * 数据库的连接
    */
   private $db;

   /**
    * 数据库的连接页面
    */
   private $pre_page = 15;


   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }

   /**
    * 列出当日的消息
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function run() {
      $now = getdate();

      $year = $this->getParameterFromGET('year');
      if ( !$year ) {
         $year = $now['year'];
      }

      $month = $this->getParameterFromGET('mon');
      if ( !$month ) {
         $month = $now['mon'];
      }

      $day = $this->getParameterFromGET('day');
      if ( !$day ) {
         $day = $now['mday'];
      }

      if ( !checkdate($month, $day, $year) ) {
         $year = $now['year'];
         $month = $now['mon'];
         $day = $now['mday'];
      }

      //取得传入的页面
      $page = $this->getParameterFromGET('page');

      if ( !$page ) {
         $page = 1;
      }


      //取得这个日期的所有事件数量
      $total_page = CalendarUtil::getTotalPage($this->db, $year, $month, $day, $this->pre_page);

      if ( $page > $total_page && $total_page > 0 ) {
         $page = $total_page;
      }

      $offset_page = ( $page - 1 ) * $this->pre_page;

      //取得当前的事件
      $event_array = CalendarUtil::getDayData($this->db, $year, $month, $day, $this->pre_page, 
         $offset_page);

      $smarty = $this->getSmarty();

      $smarty->assign('event', $event_array);

      $smarty->display('showdaydata.tmpl');




   }
}

?>
